package com.xxx.date;

import java.awt.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/19 15:45
 * @Copyright 博为峰
 */
public class CalendarDemo {
    //日历类
    public static void main(String[] args) throws ParseException {
//        m1();
//        m2();
        //Date Calendar

        String s = "2021-07-19 16:08:20";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //String-->Date
        Date date = format.parse(s);
        Calendar instance = Calendar.getInstance();
        //Date-->Calendar
        instance.setTime(date);
    }

    public static void m2() {
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.YEAR, 2008);
        instance.set(Calendar.MONTH, 8);
        instance.set(Calendar.DAY_OF_MONTH, 8);
        //加减
        instance.add(Calendar.YEAR, -1);


        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH);
        int day = instance.get(Calendar.DAY_OF_MONTH);
        System.out.println(year + "-" + month + "-" + day);
    }

    public static void m1() {
        Calendar instance = Calendar.getInstance();//工厂方法
//        System.out.println(instance);
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH);//月份从0开始
//        System.out.println(month);
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int hour = instance.get(Calendar.HOUR_OF_DAY);
        int minute = instance.get(Calendar.MINUTE);
        int second = instance.get(Calendar.SECOND);
    }
}
